<template>
  <div class="audit">
    <van-form>
      <van-field autosize readonly input-align="right"
        label="驾驶员姓名"
        v-model="formData.driver_name"
      />
      <van-field autosize readonly input-align="right"
        label="驾驶员身份证号"
        v-model="formData.driver_cardno"
      />
      <van-field autosize readonly input-align="right"
        label="驾驶员联系方式"
        v-model="formData.driver_tel"
      />
      <van-field autosize readonly input-align="right"
        label="车牌号"
        v-model="formData.car_number"
      />
      <!-- <van-field autosize readonly input-align="right"
        label="道路运输"
        v-model="formData.dlys"
      /> -->
      <van-field v-if="isInAndOuts == 2 || isInAndOuts == 3"  input-align="right" name="radio" label="是否为进口冷链">
        <template #input>
          <van-radio-group v-model="formData.car_is_ll" direction="horizontal">
            <van-radio name="1" readonly>是</van-radio>
            <van-radio name="2" readonly>否</van-radio>
          </van-radio-group>
        </template>
      </van-field>

      <div v-if="isInAndOuts == 2 || isInAndOuts == 3">
        <div v-for="(item,index) in formData.goodsList" :key="index">
        <!-- 入沈是卸货  出沈是装货-->
        <van-field input-align="right"
          v-if="index === 0 && isInAndOuts != 3"
          label="卸货区"
          readonly
          name="pattern"
          placeholder="请选择卸货区"
          v-model="formData.goodsList[index].ascription_code"
        />
        <van-field input-align="right"
          v-if="index === 0 && isInAndOuts != 1"
          label="物品装货地"
          readonly
          name="pattern"
          placeholder="请选择物品装货地"
          :value="formData.goodsList[index].goods_pretend?formData.goodsList[index].goods_pretend_s + ',' + formData.goodsList[index].goods_pretend:''"
        />
        <!-- <van-field input-align="right"
        v-if="isInAndOuts != 3"
        :label="'物品名称'+(index+1)"
        v-model="formData.goodsList[index].goods_name"
        name="pattern"
        placeholder="请输入物品名称"
        /> -->
        <!-- <van-field input-align="right"
        v-if="isInAndOuts != 3"
          :label="'物品卸货时间'+(index+1)"
          @focus="checkoutTimeChange(index)"
          readonly
          v-model="formData.goodsList[index].goods_discharge_time"
          name="pattern"
          placeholder="请输入物品卸货时间"
        /> -->
        <van-field input-align="right"
        v-if="isInAndOuts != 3"
        readonly
          :label="'物品卸货地'+(index+1)"
          v-model="formData.goodsList[index].goods_discharge"
          name="pattern"
          placeholder="请输入物品卸货地"
        />
        <van-field input-align="right"
        v-if="isInAndOuts != 3"
        readonly
          :label="'收货人姓名'+(index+1)"
          v-model="formData.goodsList[index].receiving_name"
          name="pattern"
          placeholder="请输入收货人姓名"
        />
        <van-field input-align="right"
        v-if="isInAndOuts != 3"
        readonly
          :label="'收货人联系方式'+(index+1)"
          v-model="formData.goodsList[index].receiving_tel"
          name="pattern"
          placeholder="请输入收货人联系方式"
        />
        </div>
      </div>
      <div v-for="(item,index) in formData.peerList" :key="index+'p'">
        <van-field autosize readonly input-align="right"
          :label="'同行人姓名'+(index+1)"
          v-model="formData.peerList[index].passenger_name"
        />
        <van-field autosize readonly input-align="right"
          :label="'同行人身份证号'+(index+1)"
          v-model="formData.peerList[index].passenger_cardno"
        />
        <van-field autosize readonly input-align="right"
          :label="'同行人联系方式'+(index+1)"
          v-model="formData.peerList[index].passenger_tel"
        />
      </div>
      <div v-if="formData.car_is_ll == '1'">
        <div class="title">进出口清单</div>
        <div class="img_list">
          <div @click="preview(item)" v-for="item in formData.coldchainList[0].jck_qd" :key="item"><img :src="item" alt=""></div>
        </div>
        <div class="title">进出口检疫检验证明</div>
        <div class="img_list">
          <div @click="preview(item)" v-for="item in formData.coldchainList[0].jck_jyzm" :key="item"><img :src="item" alt=""></div>
        </div>
        <div class="title">核酸检测证明</div>
        <div class="img_list">
          <div @click="preview(item)" v-for="item in formData.coldchainList[0].hs_zm" :key="item"><img :src="item" alt=""></div>
        </div>
        <div class="title">消杀证明</div>
        <div class="img_list">
          <div @click="preview(item)" v-for="item in formData.coldchainList[0].xs_zm" :key="item"><img :src="item" alt=""></div>
        </div>
      </div>
    </van-form>
    <van-field
      v-model="address"
      rows="1"
      autosize
      label="消杀地点"
      type="textarea"
      maxlength="50"
      placeholder="请输入消杀地点"
      show-word-limit
    />
    <van-field
      v-model="message"
      rows="1"
      autosize
      label="消杀部位"
      type="textarea"
      maxlength="50"
      placeholder="请输入消杀部位"
      show-word-limit
    />
    <van-button type="primary" block @click="submit">消杀</van-button>
  </div>
</template>

<script>
import { Toast, ImagePreview } from 'vant'
import { getDisinfectionCarInfo, saveDisinfectionCarInfo, getCompanyInfo } from '../../api/gov/home/index'
export default {
  name: 'sterilizationDetail',
  components: {},
  props: {},
  data () {
    return {
      isInAndOuts: 2, // 1.出沈 2.入沈 3.返沈
      message: '', // 消杀地点
      address: '', // 消杀部位
      formData: {}
    }
  },
  watch: {},
  created () {},
  mounted () {
    console.log(this.$route.query.carNumber)
    Toast.loading({
      message: '加载中...',
      forbidClick: true,
      duration: 10000
    })
    // 用车牌号查询是入沈还是返沈
    getCompanyInfo({ car_number: this.$route.query.carNumber }).then(req => {
      console.log(req, '车牌号 判断是否是返沈 入沈')
      // 1.出沈 2.入沈 3.返沈
      this.isInAndOuts = req.data.data.id ? 3 : 2
      console.log(this.isInAndOuts)
    })

    getDisinfectionCarInfo({ car_number: this.$route.query.carNumber }).then(res => {
      console.log(res, '消杀数据')
      if (res.data.errcode != 0) {
        Toast.fail(res.data.errmsg)
        const TIME = setTimeout(() => {
          this.$router.go(-1)
          clearTimeout(TIME)
        }, 1500)
      }
      const fr = ['jck_qd', 'jck_jyzm', 'hs_zm', 'xs_zm']
      fr.forEach(i => {
        if (res.data.data.coldchainList[0][i].indexOf(',') === -1) {
          res.data.data.coldchainList[0][i] = [res.data.data.coldchainList[0][i]]
        } else {
          res.data.data.coldchainList[0][i] = res.data.data.coldchainList[0][i].split(',')
        }
      })
      this.formData = res.data.data
      Toast.clear()
    })
  },
  computed: {},
  methods: {
    preview (img) {
      ImagePreview([img])
    },
    submit () {
      Toast.loading({
        message: '加载中...',
        forbidClick: true,
        duration: 10000
      })
      console.log({
        disinfection_wz: this.address,
        disinfection_bw: this.message,
        car_number: this.$route.query.carNumber
      }, '消杀提交的数据')
      saveDisinfectionCarInfo({
        disinfection_wz: this.address,
        disinfection_bw: this.message,
        car_number: this.$route.query.carNumber
      }).then(res => {
        console.log(res)
        Toast.clear()
        if (res.data.errcode == 0) {
          Toast.success('消杀成功')
          const TIME = setTimeout(() => {
            this.$router.go(-1)
            clearTimeout(TIME)
          }, 1500)
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
.audit{
  .title{
    padding: 0.533rem 0.853rem;
    font-size: 0.747rem;
  }
  /deep/.van-field__label{
    width: 8em;
  }
  .img_list{
    margin: 20px 0.853rem;
    display: flex;
    img{
      width: 120px;
      height: 120px;
      margin-right: 20px;
    }
  }
}
</style>
